﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.Mobile.Utilities;

namespace OgilvyOne.UKNow.Mobile.APIs.Events
{
   public class CheckFavorite:IHttpHandler
    {
       public bool IsReusable
       {
           get { return true; }
       }

       public void ProcessRequest(HttpContext context)
       {
           var userid = context.Request.QueryString["uid"];
           var eventid = context.Request.QueryString["eventid"];
           int uid = 0;
           int eid = 0;
           if (int.TryParse(userid, out uid))
           {

           }
           if (int.TryParse(eventid, out eid))
           {

           }
           if (uid > 0 && eid > 0)
           {
               var result = new EventsBLL(2052).CheckUserFavEvent(uid, eid);

               context.Response.Write(ResultUtility.ReturnResultJson("0", "{" + String.Format("\"flag\":\"{0}\"", result) + "}", result ? "用户已收藏该活动" : "用户未收藏该活动"));

               //IList<FavoriteEventsModel> list = new EventsBLL(2052).GetMyEvents(uid, DateTime.Now.ToString(), "", true);
               //if (list != null && list.Count > 0)
               //{
               //    context.Response.Write(ResultUtility.ReturnResultJson("0", "{" + String.Format("\"flag\":\"{0}\"", true) + "}", "用户已收藏该活动"));
               //}
               //else
               //{
               //    context.Response.Write(ResultUtility.ReturnResultJson("0", "{" + String.Format("\"flag\":\"{0}\"", false) + "}", "用户未收藏该活动"));
               //}
           }
           else
           {
               context.Response.Write(ResultUtility.ReturnResultJson("-701", "", "参数错误"));
           }
       }
    }
}
